import sys, getopt
from model import *
from querymanager import *

if __name__ == "__main__":
    try:
        ml = sys.argv[1]
        opts, args = getopt.getopt(sys.argv[2:],'l:p:', ['mnb','svm'])
    except:
        print '''Usage: python zillion.py <-mnb|-svm> <-l labFileName.txt> <-p pagerankfile.txt> <dict.txt> <postings.txt>
        Example: python zillion.py -svm -f collections/labSVM.txt collections/dict.txt collections/post.txt'''
        sys.exit(1)

    labfile = ''
    pagerankfile = ''
    for o, a in opts:
        if o == '-l':
            labfile = a
        elif o == '-p':
            pagerankfile = a
    dictfile = args[0]
    postingfile = args[1]

    if ml == '-mnb':
        index = Index.fromFile(dictfile, postingfile, pagerankfile=pagerankfile, labmnb=labfile, advanced=True)
    elif ml == '-svm':
        index = Index.fromFile(dictfile, postingfile, pagerankfile=pagerankfile, labsvm=labfile, advanced=True)
        
    qm = QueryManager(index)
    LIMIT = 10
    line = sys.stdin.readline()
    while line:
        qm.handle(input=line, limit=LIMIT, ranked=True, advanced=ml)
        line = sys.stdin.readline()
    
    